<script setup>
import {
    Edit,Delete,Position,Upload
} from '@element-plus/icons-vue'
import {

} from '@/api/allApi.js'
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
    addpathservice, getallbookservice,getpartpathservice,
    updatepathservice, detailbookservice, deletepathservice, lendbookservice, getallbookcategoryservice
} from '@/api/book.js'
import {getpartf2service,deletef2service} from '@/api/allApi.js'
//控制添加分类弹窗
const dialogVisible = ref(false)
const lenddialogVisible = ref(false)
//分页条数据模型
//const pageNum = ref(1)//当前页
const total = ref(20)//总条数
//const pageSize = ref(3)//每页条数
//文章分类数据模型
const categorys = ref([
])
//用户搜索时选中的分类id
const categoryId = ref('')
const bookcategorylist = async () => {
    let result = await getallbookcategoryservice();
    categorys.value = result.data;
}
bookcategorylist();
//用户搜索时选中的发布状态
const state = ref('')
//定义变量，控制标题
const title = ref('')
const f1 =ref(false)
const f2 =ref(false)
const f3 =ref(false)
const f4 =ref(false)
//交通路线列表数据模型
const paths = ref([
])
const allpoint = ref(['北京','广州','贵阳','哈尔滨','兰州',
'青岛','上海','乌鲁木齐','郑州','重庆'])
const allway = ref(['飞机','火车','船'])
//与后端交互的json数据
const pathmodel = ref({
    startPoint: '', //起点
    endPoint: '', //终点
    number: '', //班次
    startTime: null, //出发时间
    endTime: null, //到达时间
    price: '', //费用
    way:'' //交通方式
})
const sheets = ref([])
const sheetmodel = ref([{
    id:null, //各种记录表的编号
    damageType:null,
    damageDescribe:null,
    comment:null,
    damagePart:null,
    damageReason:null,
    facilityName:null,
    suggest:null,
    IRI:null,
    allLongth:null,
    allWidth:null,
    damageLongth:null,
    damageWidth:null,
    damageHighth:null,
    damageArea:null,

    sheetName:null,
    finishTime:null,
    userName:null,
    pathId:null,
    pathName:null,
    startAddress:null,
    endAddress:null
}])

const findmodel = ref({
    pageNum: 1,
    pageSize: 20,
    startPoint: '',
    endPoint:'',
    str: ''
})
const f2list = async () => {
    console.log(findmodel.value);
    let result = await getpartf2service(findmodel.value);
    console.log(result);
    total.value = result.data.total;
    sheets.value = result.data.items;
}
f2list();
//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
    findmodel.value.pageSize = size;
    f2list();
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
    findmodel.value.pageNum = num;
    f2list();
}
const cleardata = () => {
    findmodel.value.startPoint = '',
    findmodel.value.endPoint = '',
    findmodel.value.str = ''
}
//表单校验
const rules = {
    startPoint: [
        { required: true, message: '请选择出发地', trigger: 'blur' },
    ],
    endPoint: [
        { required: true, message: '请选择目的地', trigger: 'blur' },
    ],
    number: [
        { required: true, message: '请输入班次', trigger: 'blur' },
    ],
    startTime: [
        { required: true, message: '请输入出发时间', trigger: 'blur' },
    ],
    endTime: [
        { required: true, message: '请输入到达时间', trigger: 'blur' },
    ],
    price: [
        { required: true, message: '请输入费用', trigger: 'blur' },
    ],
    way: [
        { required: true, message: '请选择交通方式', trigger: 'blur' },
    ]
}
const add = () => {
    pathmodel.value.startPoint = ''
    pathmodel.value.endPoint = ''
    pathmodel.value.number = ''
    pathmodel.value.startTime = ''
    pathmodel.value.endTime = ''
    pathmodel.value.price = 0
    pathmodel.value.way = ''
    dialogVisible.value = true;
    title.value = '添加商品'
}
const addpath = async () => {
    console.log(pathmodel.value);
    let result = await addpathservice(pathmodel.value);
    if (result.code == 0) {
        ElMessage.success("添加成功")
        dialogVisible.value = false;
        pathlist();
    }
    else {
        ElMessage.error(result.message ? result.message : '添加失败')
    }
}
const updatepath = async () => {
    console.log(pathmodel.value);
    let result = await updatepathservice(pathmodel.value);
    if (result.code == 0) {
        ElMessage.success("修改成功")
        dialogVisible.value = false;
        pathlist();
    }
    else {
        ElMessage.error(result.message ? result.message : '修改失败')
    }
}
//删除分类
const del = (row) => {
    ElMessageBox.confirm(
        '你确认删除该条记录表信息吗？',
        '温馨提示',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(async () => {
            //用户点击了确认
            let result = await deletef2service(row.id)
            if(result.code == 0 ){
                ElMessage.success('删除成功')
                f2list();
            }
            else{
                ElMessage.error('删除失败')
            }
        })
        .catch(() => {
            //用户点击了取消
            ElMessage({
                type: 'info',
                message: '取消删除',
            })
        })
}
//展示编辑弹窗
const showDialog = (row) => {
    title.value = row.sheetName;
    console.log(row.sheetName);
    if(row.sheetName ==='道路设施日常巡查情况记录表'){
        f1.value=true;
    }
    else if(row.sheetName==='设施损害通知单'){
        f2.value=true;
    }
    else if(row.sheetName==='道路路面平整度检测记录表'){
        f3.value=true;
    }
    else if(row.sheetName==='道路设施路面损害情况记录表'){
        f4.value=true;
    }
    //数据拷贝
    sheetmodel.value[0].finishTime = sheets.value[0].taskName
    console.log(sheetmodel.value[0]);
    //扩展i的属性，将来需要传递给后台，完成分类的修改
    console.log(row.id);

    // taskmodel.value.recordId = 2
    //数据拷贝
    sheetmodel.value[0].damageType = row.damageType
    sheetmodel.value[0].damageDescribe = row.damageDescribe
    sheetmodel.value[0].comment = row.comment
    sheetmodel.value[0].damagePart = row.damagePart
    sheetmodel.value[0].damageReason = row.damageReason
    sheetmodel.value[0].facilityName = row.facilityName
    sheetmodel.value[0].suggest = row.suggest
    sheetmodel.value[0].IRI = row.IRI
    sheetmodel.value[0].allLongth = row.allLongth
    sheetmodel.value[0].allWidth = row.allWidth
    sheetmodel.value[0].damageLongth = row.damageLongth
    sheetmodel.value[0].damageWidth = row.damageWidth
    sheetmodel.value[0].damageHighth = row.damageHighth
    sheetmodel.value[0].damageArea = row.damageArea

    // sheetmodel.value[0].finishTime = row.finishTime
    sheetmodel.value[0].userName = row.userName
    sheetmodel.value[0].pathId = row.pathId
    sheetmodel.value[0].pathName = row.pathName
    sheetmodel.value[0].startAddress = row.startAddress
    sheetmodel.value[0].endAddress = row.endAddress
    //扩展i的属性，将来需要传递给后台，完成分类的修改
    // sheetmodel.value[0].id = row.id; //task的id
    console.log(row.id);
}


</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>设施损害通知单</span>
                <div class="extra">
                    <!-- <el-button type="primary" @click="add">添加商品</el-button> -->
                </div>
            </div>
        </template>
        <!-- 搜索表单 -->
        <el-form inline>
            <el-form-item label="查询条件：">
                <el-input v-model="findmodel.str" placeholder="请输入查询内容" width="200"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="f2list">搜索</el-button>
                <el-button @click="cleardata">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 文章列表 -->
        <el-table :data="sheets" style="width: 100%">
            <el-table-column label="序号" width="60" type="index"> </el-table-column>
            <el-table-column label="提交日期" prop="finishTime" > </el-table-column>
            <el-table-column label="巡查人员" prop="userName" > </el-table-column>
            <el-table-column label="道路名称" prop="pathName" width="80"></el-table-column>
            <el-table-column label="设施名称" prop="facilityName" width="140"></el-table-column>
            <el-table-column label="损坏部位" prop="damagePart" ></el-table-column>
            <el-table-column label="损坏原因" prop="damageReason" ></el-table-column>
            <el-table-column label="处理意见" prop="suggest" ></el-table-column>
            <!-- <el-table-column label="路面类型" prop="pavementType" ></el-table-column> -->
            <!-- <el-table-column label="起始地址" prop="startAddress" ></el-table-column>
            <el-table-column label="结束地址" prop="endAddress" > </el-table-column> -->
            <!-- <el-table-column label="提交日期" prop="finishTime" width="180"> </el-table-column> -->
            
            <el-table-column label="操作" width="60">
                <template #default="{ row }">
                    <!-- <el-button v-if="row.taskName === '日常检查'" :icon="Position" circle plain @click="elsesubmit(row)"></el-button> -->
                    <!-- <el-button  plain type="primary" @click="showDialog(row)">查看详情</el-button> -->
                    <el-button :icon="Delete" circle plain type="danger" @click="del(row)"></el-button>
                </template>
            </el-table-column>
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>
        <!-- 分页条 -->
        <el-pagination v-model:current-page="findmodel.pageNum" v-model:page-size="findmodel.pageSize"
            :page-sizes="[20, 30, 40, 50]" layout="jumper, total, sizes, prev, pager, next" background :total="total"
            @size-change="onSizeChange" @current-change="onCurrentChange"
            style="margin-top: 20px; justify-content: flex-end" />
    </el-card>
    <!-- 添加分类弹窗 -->
    <!-- <el-dialog v-model="dialogVisible" :title="title" width="40%">
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="date" label="Date" width="180" />
            <el-table-column prop="name" label="Name" width="180" />
            <el-table-column prop="address" label="Address" />
        </el-table>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="title == '添加商品' ? addpath() : updatepath()"> 确认 </el-button>
            </span>
        </template>
    </el-dialog> -->
    <!-- 添加f1弹窗 -->
    <el-dialog v-model="f1" :title="title" width="80%">
        <!-- <h3>111</h3> -->
        <el-table :data="sheetmodel" border style="width: 100%">
            <el-table-column prop="finishTime" label="日期" />
            <el-table-column prop="name" label="巡查人员"  />
            <el-table-column prop="pathId" label="道路编号" />
            <el-table-column prop="pathName" label="道路名称" />
            <el-table-column prop="damageType" label="损坏类型" />
            <el-table-column prop="damageDescribe" label="损坏位置及损坏情况描述" width="200"/>
            <el-table-column prop="comment" label="备注" />
        </el-table>
        <template #footer>
            <span class="dialog-footer">
                <!-- <el-button @click="f1 = false">取消</el-button>
                <el-button type="primary" @click="addf1"> 确认 </el-button> -->
            </span>
        </template>
    </el-dialog>
        <!-- 添加f2弹窗 -->
        <el-dialog v-model="f2" :title="title" width="80%">
        <el-table :data="sheetmodel" border style="width: 100%">
            <!-- <el-table-column prop="finishTime" label="日期" /> -->
            <el-table-column prop="name" label="巡查人员"  />
            <el-table-column prop="pathId" label="道路编号" />
            <el-table-column prop="pathName" label="道路名称" />
            <el-table-column prop="facilityName" label="设施名称" />
            <el-table-column prop="damagePart" label="损坏部位" />
            <el-table-column prop="damageReason" label="损坏原因" width="200"/>
            <el-table-column prop="suggest" label="处理意见" />
        </el-table>
        <template #footer>
            <span class="dialog-footer">
                <!-- <el-button @click="f1 = false">取消</el-button>
                <el-button type="primary" @click="addf1"> 确认 </el-button> -->
            </span>
        </template>
    </el-dialog>
        <!-- 添加f3弹窗 -->
        <el-dialog v-model="f3" :title="title" width="60%">
        <!-- <h3>111</h3> -->
        <el-table :data="sheetmodel" border style="width: 100%">
            <el-table-column prop="finishTime" label="日期" />
            <el-table-column prop="name" label="检测人员"  />
            <el-table-column prop="pathId" label="道路编号" />
            <el-table-column prop="pathName" label="道路名称" />
            <el-table-column prop="IRI" label="IRI" />
            <el-table-column prop="comment" label="备注" />
        </el-table>
        <template #footer>
            <span class="dialog-footer">
                <!-- <el-button @click="f1 = false">取消</el-button>
                <el-button type="primary" @click="addf1"> 确认 </el-button> -->
            </span>
        </template>
    </el-dialog>
        <!-- 添加f4弹窗 -->
        <el-dialog v-model="f4" :title="title" width="80%">
        <!-- <h3>111</h3> -->
        <el-table :data="sheetmodel" border style="width: 100%">
            <el-table-column prop="finishTime" label="日期" />
            <el-table-column prop="name" label="检查人员"  />
            <el-table-column prop="pathId" label="道路编号" />
            <el-table-column prop="pathName" label="道路名称" />
            <el-table-column prop="damageType" label="起始位置" />
            <el-table-column prop="damageType" label="结束位置" />
            <el-table-column prop="damageType" label="检查总长" width="40"/>
            <el-table-column prop="damageType" label="检查总宽" width="40"/>
            <el-table-column prop="damageType" label="损坏类型" width="40"/>
            <el-table-column prop="damageType" label="损坏长" width="40"/>
            <el-table-column prop="damageType" label="损坏宽" width="40"/>
            <el-table-column prop="damageType" label="损坏高" width="40"/>
            <el-table-column prop="damageDescribe" label="损坏位置及损坏情况描述" />
            <el-table-column prop="damageArea" label="损坏面积" />
            <el-table-column prop="comment" label="备注" />
        </el-table>
        <template #footer>
            <span class="dialog-footer">
                <!-- <el-button @click="f1 = false">取消</el-button>
                <el-button type="primary" @click="addf1"> 确认 </el-button> -->
            </span>
        </template>
    </el-dialog>
</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;
    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>